<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;

Route::get('think', function () {
    return 'hello,ThinkPHP8!';
});

//Route::get('hello/:name', 'index/hello');
//
////用户模块路由
//Route::resource('user', 'User');
////权限模块路由
//Route::resource('auth', 'Auth');

//后台组
Route::group(function () {
//用户模块资源路由
    Route::resource('/user', 'User');
//权限模块资源路由
    Route::resource('/auth', 'Auth');
})->middleware(function ($request, \Closure $next) {
    if (!session('?admin')) {
        return redirect('/login');
    }
    return $next($request);
});

//上传
Route::resource('upload', 'upload');
//登录路由
Route::group(function () {
//    Route::get('login', 'Login/index');
    Route::get('login', 'Login/index')->middleware(function ($request, Closure $next) {
        if (session('?admin')) {
            return redirect('/');
        }
        return $next($request);
    });
    Route::post('login_check', 'Login/check');
});


//退出登录
Route::get('logout', 'Login/logout');